﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Willow.Authorization;
using Willow.IRepository;
using Willow.IService.Sys;
using Willow.Model;

namespace Willow.Service.Sys
{
    public class DictionaryTypeService : BaseService<Sys_DictionaryType>, IDictionaryTypeService
    {
        public DictionaryTypeService(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        /// <summary>
        /// 保存字典类型
        /// </summary>
        /// <param name="TObject">The t object.</param>
        public override void Save(Sys_DictionaryType TObject)
        {
            var currUser = OnlineContext.Instance.GetCurrentUser();
            if (TObject.Id == default(Guid))
            {
                TObject.Id = Guid.NewGuid();
                TObject.CreateTime = DateTime.Now;
                TObject.CreateUserId = currUser.UserId;
                TObject.IsDelete = false;
                this.Create(TObject);
            }
            else
            {
                var orglType = this.Find(TObject.Id);
                orglType.Remark = TObject.Remark;
                orglType.Name = TObject.Name;
                orglType.UpdateTime = DateTime.Now;
                orglType.UpdateUserId = currUser.UserId;
                this.Update(orglType);
            }
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id">The identifier.</param>
        public void LogicalDelete(Guid id)
        {
            var obj = this.Find(id);
            obj.IsDelete = true;
            this.Update(obj);
        }
    }
}
